<?

function V_Gallery($arrayData, $arrayData_Gallery_type) {
    $ulr = "?" . MODUL . "=gallery&" . ACTION . "=";
    $totalRows = 0;
    $curPage = 1;
    $strStart = 0;
    $strEnd = 0;
    $curPage = CM_getParameter("curPg");
    if (((int) $curPage) == 0)
	$curPage = 1;

    $totalRows = count($arrayData);

    $totalPage = (int) ($totalRows / NUM_ROW_ON_PAGE_PRODUCT);
    if ($totalRows % NUM_ROW_ON_PAGE_PRODUCT > 0)
	$totalPage++;

    if ($totalRows > 0) {
	$strStart = ($curPage - 1) * NUM_ROW_ON_PAGE_PRODUCT + 1;
	$strEnd = ($curPage ) * NUM_ROW_ON_PAGE_PRODUCT;
	if ($strEnd > $totalRows)
	    $strEnd = $totalRows;
    }
    $parent_id = CM_getParameter('parent_id');
    if ($parent_id != "") {
	$url = "&parent_id=$parent_id";
    }
    $lable_type = $arrayData_Gallery_type['gallery_type_name'];
    if ($lable_type == "") {
	$lable_type = "Tất cả ảnh";
    }
    ?>
    <script type="text/javascript" src="../../javascript/lightbox/lib/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="../../javascript/lightbox/source/jquery.fancybox.js?v=2.1.5"></script>
    <link rel="stylesheet" type="text/css" href="../../javascript/lightbox/source/jquery.fancybox.css?v=2.1.5" media="screen" />
    <script type="text/javascript">
        $(document).ready(function() {
    	$(".fancybox-effects-b").fancybox({
    	    openEffect: 'none',
    	    closeEffect: 'none',
    	    helpers: {
    		title: {
    		    type: 'over'
    		}
    	    }
    	});
        });
    </script>
    <script>
        function GotoPage(iPage) {
    	document.frm.action = document.frm.action + "&curPg=" + iPage;
    	document.frm.submit();
        }
    </script>
        <script>
    function Add_service_type() {
	window.location.href = "?modul=gallery&action=add_pic";
    }
</script>
    <div>
        <form name="frm" action="<?= $ulr ?>List<?= $url ?>"  method="post" enctype="multipart/form-data">
    	<h3><?= $lable_type ?></h3>
	 <p style="float: right"><input type="button" value="Thêm mới" onclick="Add_service_type();" /></p>
    	<table border="1" width="100%" cellpadding="5">
	     <tr style="background-color: #99CCFF">
		<th width="10px">STT</th>
		<th width="200px">Ảnh</th>
		<th>Thông tin</th>
		<th width="10px">Sửa</th>
		<th width="10px">Xóa</th>
	    </tr>
		<?
		if (!empty($arrayData)) {
		    $i = 0;
		    $curRow = 0;
		    foreach ($arrayData as $value) {
			$curRow++;
			$i++;
			if ($curRow < $strStart)
			    continue;
			if ($curRow > $strEnd)
			    break;
			?>
	    	    <tr>
	    		<td rowspan="2"><?=$i?></td>
	    		<td rowspan="2">
			    <img width="200px" src="<?=DIR_IMG_SLIDE_GALLERY.$value['url_pic']?>"/>
			</td>
	    		<td>
			    <b>Tên ảnh: </b><?=$value['name_pic']?>
			</td>
			<td rowspan="2"><a href="<?=$ulr."Edit_pic&id=".$value['id']?>">Sửa</a></td>
			<td rowspan="2"><a onclick="return confirm('Bạn có chắc chắn muốn xóa ảnh này không?');" href="<?=$ulr."Del_pic&id=".$value['id']?>">Xóa</a></td>
	    	    </tr>
	    	    <tr>
	    		<td>			
			    <b>Ghi chú:</b><br/>
			<?=$value['notes_pic']?>
			</td>
	    	    </tr>
			<?
		    }
		    ?>
		</table>
		<br/>
		<br/>
		<div style="margin-top: 20px;float: right">
		    <?
		    $page = CM_getParameter("curPg");
		    if ($page == '') {
			$page = 1;
		    }
		    ?>
		    Trang thứ : <span style="color:#F00;"><?= $page ?></span>&nbsp;&nbsp;Tổng số trang: <span style="color:#F00;"><?= $totalPage ?></span><br />

		    <?
		    if ($totalPage > 1) {
			echo "<a href =\"javascript:GotoPage('1')\" style=\"text-decoration:none; \">&laquo; Trang đầu</a>&nbsp;&nbsp;&nbsp;";
			for ($i = 1; $i <= $totalPage; $i++) {
			    if ($i < $curPage + 5 && $i > $curPage - 5) {

				if ($i != $curPage)
				    echo "<a href=\"javascript:GotoPage('$i')\" style=\"text-decoration:none; \">$i</a>&nbsp;&nbsp;";
				else
				    echo "<SPAN class=bk12-140 style=\"color:#FF0000;\">$i&nbsp;&nbsp;</SPAN>";
			    }
			}
			echo "&nbsp;&nbsp;&nbsp;<a href =\"javascript:GotoPage('" . $totalPage . "')\" style=\"text-decoration:none; \">Trang cuối &raquo;</a>  ";
		    }
		    ?>
		</div>
		<?
	    } else {
		echo "Hiên tại chưa có sản phẩm nào !.";
	    }
	    ?>
        </form>
    </div>
    <?
}
?>